﻿using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Xml;
namespace WPFExcelReport
{
    public partial class JLTAB55DOCReport : BaseReport
    {

        private void FillInAB55WF()
        {
            string value = "";
            DataRow dwABPOS = null;
            int rStart = 0;
            int nRow = 1;
            int nPRow = 1;
            int idx = 0;
            int pages = 0;
            dwABPOS = dsSource.Tables["ABPOS"].Rows[0];

            DataRow dwABK = dsSource.Tables["ABKOPF"].Rows[0];
            DataRow dwWS = null;
            if (dsSource.Tables["WASTAMM"].Rows.Count > 0)
            {
                dwWS = dsSource.Tables["WASTAMM"].Rows[0];
            }
            string art = dwABPOS["ABPART"].ToString();
            string var = dwABPOS["ABPVAR"].ToString();
            string color = dwABPOS["ABPFARBE"].ToString();
            #region====Header======
            exAgent.SetCellValue(1, 23, "*" + dwABPOS["ABPAUFKRS"].ToString() + dwABPOS["ABPAUFLFD"].ToString() + dwABPOS["ABPAUFPOS"].ToString() + "*");//barcode

            exAgent.SetCellValue(3, 5, dwABPOS["ABPAUFKRS"].ToString() + "-" + Helpers.Helper.GetSubRollNum(dwABPOS["ABPAUFLFD"].ToString())
                + "-" + Helpers.Helper.GetSubRollNum(dwABPOS["ABPAUFPOS"].ToString()));
            exAgent.SetCellValue(3, 15, dwABK["ABKKDAUFTNR"].ToString());
            exAgent.SetCellValue(3, 29, Today);
            if (dwWS != null)
            {
                exAgent.SetCellValue(4, 5, GetGB2312Value(dwWS["WABEZ"].ToString()));
            }
            exAgent.SetCellValue(8, 5, dwABPOS["ABPFILLER1"].ToString());
            #endregion


            #region====yarn=========
            rStart = 16;
            nRow = 2;
            nPRow = 2;
            idx = 0;
            int ycount = dsSource.Tables["GAAUF"].Rows.Count;
            foreach (DataRow rw in dsSource.Tables["GAAUF"].Rows)
            {
                string gaart = rw["GAART"].ToString();
                string gavar = rw["GAVAR"].ToString();
                string gacolor = rw["GAFARBE"].ToString();
                double gakg1 = System.Convert.ToDouble(rw["GAKG1"].ToString()) * 0.01;
                double gakg5 = System.Convert.ToDouble(rw["GAKG5"].ToString()) * 0.01;
                string yarn = gaart.Trim();
                if (gavar.Trim() != "")
                    yarn += "/" + gavar.Trim();
                if (gacolor.Trim() != "")
                {
                    if (gacolor.Trim() != "000000")
                    {
                        yarn += "/" + gacolor.Trim();
                    }
                }

                exAgent.SetCellValue(rStart + idx * nRow, 3, yarn);
                exAgent.SetCellValue(rStart + idx * nRow, 19, gakg1);
                exAgent.SetCellValue(rStart + idx * nRow, 22, gakg5);
                var query = from DataRow row in dsSource.Tables["WASTGA"].AsEnumerable()
                            where row["WAGGART"].ToString() == gaart
                            && row["WAGGVAR"].ToString().Trim() == gavar.Trim()
                            && row["WAGGFARBE"].ToString() == gacolor
                            select row;
                foreach (DataRow row in query)
                {
                    //exAgent.SetCellValue(rStart + idx * nRow, 15, row["WAGFDZ"].ToString());
                }
                query = from DataRow row in dsSource.Tables["ZUTEI"].AsEnumerable()
                        where row["ZUAUFKRS"].ToString() == rw["GAAUFKRS"].ToString()
                        && row["ZUAUFLFD"].ToString() == rw["GAAUFLFD"].ToString()
                        && row["ZUAUFPOS"].ToString() == rw["GAAUFPOS"].ToString()
                        select row;
                foreach (DataRow row in query)
                {
                    exAgent.SetCellValue(rStart + idx * nRow, 15, row["ZUSPPART"].ToString());
                }
                idx++;
                if (idx < ycount)
                {
                    exAgent.RangeCopy(16, 17, rStart + idx * nRow, rStart + idx * nRow + 1);
                }
            }

            #endregion
            #region=========footer===========
            exAgent.SetCellValue(rStart + idx + 3, 2, "制表人：			_____________");
            exAgent.SetCellValue(rStart + idx + 3 + 1, 2, "日期：			_____________");
            exAgent.SetCellValue(rStart + idx + 3, 10, "主管：			_____________");
            exAgent.SetCellValue(rStart + idx + 3 + 1, 10, "日期：			_____________");
            exAgent.SetCellValue(rStart + idx + 3, 23, "经理：			_____________");
            exAgent.SetCellValue(rStart + idx + 3 + 1, 23, "日期：			_____________");
            #endregion
        }
    }
}